//
//  NewsChannelViewController.m
//  DemoV2
//  比较简单就都写controller了
//  Created by 董一龙 on 2022/6/25.
//

#import "../Common.h"
#import "NewsChannelViewController.h"
#import <WebKit/WebKit.h>

@interface NewsChannelViewController ()

@property (nonatomic, strong, readwrite) WKWebView *webview;
@property (nonatomic, strong, readwrite) UIProgressView *progressView;

@end

@implementation NewsChannelViewController

- (instancetype)init{
    if(self = [super init]){
        self.tabBarItem.title = @"新闻";
        self.tabBarItem.image = kGetImage(@"zhenzhunaicha.png");
        self.view.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)dealloc{
    [self.webview removeObserver:self forKeyPath:@"estimatedProgress"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.webview = [[WKWebView alloc] initWithFrame:CGRectMake(0, 88, self.view.frame.size.width, self.view.frame.size.height - 88)];
    [self.view addSubview: self.webview];
    
    [self.webview loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://news.qq.com"]]];
    
    [self.webview addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
    
    self.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 88, self.view.frame.size.width, 20)];
    
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    self.progressView.progress = self.webview.estimatedProgress;
}


@end
